<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"PB-4-1");
mysql_select_db($database_con_gl, $con_gl);
$query_kontak = "SELECT id, nama, type FROM gl_kontak where `type`='Supplier' ORDER BY type, nama ASC";
$kontak = mysql_query($query_kontak, $con_gl) or die(mysql_error());
$row_kontak = mysql_fetch_assoc($kontak);
$totalRows_kontak = mysql_num_rows($kontak);

mysql_select_db($database_con_gl, $con_gl);
$query_klaskas = "SELECT kd, klasifikasi FROM gl_klas WHERE tipe = 2 ORDER BY kd,klasifikasi ASC";
$klaskas = mysql_query($query_klaskas, $con_gl) or die(mysql_error());
$row_klaskas = mysql_fetch_assoc($klaskas);
$totalRows_klaskas = mysql_num_rows($klaskas);

mysql_select_db($database_con_gl, $con_gl);
$query_def_ak = "SELECT gl_company.a_kas FROM gl_company";
$def_ak = mysql_query($query_def_ak, $con_gl) or die(mysql_error());
$row_def_ak = mysql_fetch_assoc($def_ak);
$totalRows_def_ak = mysql_num_rows($def_ak);
// ---
mysql_select_db($database_con_gl, $con_gl);
$query_gudang = "SELECT id, gudang FROM gl_gudang";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gudang .= " where id='$_SESSION[lokasi]'";
}
$query_gudang .=" ORDER BY gudang ASC";
$gudang = mysql_query($query_gudang, $con_gl) or die(mysql_error());
$row_gudang = mysql_fetch_assoc($gudang);
$totalRows_gudang = mysql_num_rows($gudang);
?>
<link href="css/ui.datepicker.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/ajax_data.js"></script>
<script type="text/javascript" src="js/jquery-1.2.3.js"></script>
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function()
      {
        $('.calendar').datepicker({
            appendText : "yyyy/mm/dd",
            dateFormat : 'yy/mm/dd'
          });
      });
</script>
<script type="text/javascript">
$(document).ready(function() {

	$().ajaxStart(function() {
		$('#loading').show();
		$('#result').hide();
	}).ajaxStop(function() {
		$('#loading').hide();
		$('#result').fadeIn('slow');
	});

	$('#add').submit(function() {
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data) {
				$('#result').html(data);
			}
		})
		return false;
	});
  $('#result').click(function(){
  $(this).hide();
  });
})
</script>
<div id="loading" style="display:none;"><img src="images/loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<h1>Tambah Pembayaran Hutang</h1>
<form action="proses/pembayaranhutang.php?act=add" method="POST" name="add" id="add">
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr>
      <td align="right" valign="top">Akun Kas *: </td>
      <td valign="top"><label>
      <select name="akunkas" id="akunkas">
        <?php
do {  
mysql_select_db($database_con_gl, $con_gl);
$query_kasakun = "SELECT id, akun FROM gl_akun where klasifikasi='$row_klaskas[kd]' ORDER BY akun ASC";
$kasakun = mysql_query($query_kasakun, $con_gl) or die(mysql_error());
$row_kasakun = mysql_fetch_assoc($kasakun);
$totalRows_kasakun = mysql_num_rows($kasakun);
?>
        <option value="" style="background:#DDDDDD;font-weight:bold;"><?php echo $row_klaskas['klasifikasi']?></option>
        <?php if($totalRows_kasakun > 0) { ?>
        <?php do { ?>
        <option value="<?php echo $row_kasakun['id']; ?>" <?php if($row_kasakun['id']==$row_def_ak['a_kas']) { ?>selected="selected"<?php } ?>>-<?php echo $row_kasakun['akun']; ?></option>
        <?php } while ($row_kasakun = mysql_fetch_assoc($kasakun)); ?>
        <?php } ?>
        <?php
} while ($row_klaskas = mysql_fetch_assoc($klaskas));
  $rows = mysql_num_rows($klaskas);
  if($rows > 0) {
      mysql_data_seek($klaskas, 0);
	  $row_klaskas = mysql_fetch_assoc($klaskas);
  }
?>
      </select>
      </label></td>
      <td align="right" valign="top">Kepada *: </td>
      <td valign="top"><label>
      <select name="kepada" id="kepada" onchange="setInvoice(this.value);">
        <option value="">Pilih Kontak</option>
        <?php
do {  
?>
        <option value="<?php echo $row_kontak['id']?>"><?php echo $row_kontak['nama']?> (<?php echo $row_kontak['type']; ?>)</option>
        <?php
} while ($row_kontak = mysql_fetch_assoc($kontak));
  $rows = mysql_num_rows($kontak);
  if($rows > 0) {
      mysql_data_seek($kontak, 0);
	  $row_kontak = mysql_fetch_assoc($kontak);
  }
?>
      </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top">No. Referensi *:</td>
      <td valign="top"><label>
        <input name="noreferensi" type="text" id="noreferensi" value="BO<?php echo time();?>" size="20" maxlength="20" />
      </label></td>
      <td align="right" valign="top">Lokasi Kantor *:</td>
      <td valign="top"><label>
        <select name="gudang" id="gudang">
          <?php
do {  
?>
          <option value="<?php echo $row_gudang['id']?>"><?php echo $row_gudang['gudang']?></option>
          <?php
} while ($row_gudang = mysql_fetch_assoc($gudang));
  $rows = mysql_num_rows($gudang);
  if($rows > 0) {
      mysql_data_seek($gudang, 0);
	  $row_gudang = mysql_fetch_assoc($gudang);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top">      Tanggal *: </td>
      <td valign="top"><label>
          <input name="tanggal" type="text" class="calendar" id="tanggal" value="<?php echo date("Y/m/d"); ?>" size="20" maxlength="15"/>
      </label></td>
      <td align="right" valign="top">Keterangan :</td>
      <td valign="top"><label>
      <textarea name="keterangan" cols="40" rows="2" id="keterangan">Pembayaran Hutang Usaha</textarea>
      </label></td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td colspan="3"><div id="ajaxDiv">
	      <table width="100%" border="0" cellspacing="0" cellpadding="5" class="datatable">
            <tr>
              <th align="center"><strong>Invoice</strong></th>
              <th align="center"><strong>Nilai (D) </strong></th>
              <th align="center"><strong>Transaksi</strong></th>
              <th width="15%" align="center"><strong>Aksi</strong></th>
            </tr>
            <tr valign="top" bgcolor="#FFFFFF">
              <td align="center" style="background:none;border:none;"><div id="divInvoice">
                <label>
                <select name="invoice" id="invoice" style="width:400px;">
                  <option style="background:#EEEEEE;font-weight:bold;" value="">Pilih Invoice</option>
                </select>
                </label>
              </div></td>
              <td align="center" style="background:none;border:none;"><div id="divTotal"><label>
                <input name="nilai" type="text" id="nilai" size="10" onchange="javascript:if(this.value > 0) { this.form.debet.value='';}else{ alert('Value invalid !!!');this.value='';}"/>
              </label></div></td>
              <td align="center" style="background:none;border:none;"><div id="divTransaksi"><label>
              <textarea name="transaksi" cols="50" rows="2" id="transaksi"></textarea>
              </label></div></td>
              <td align="center" style="background:none;border:none;"><label></label>
                  <label>
                  <input name="add" type="button" id="add" value="&nbsp;" onclick="ajaxManagePembayaranHutang('Tambah');" class="checkbutton" title="Tambah Transaksi"/>
              </label></td>
            </tr>
          </table>
		  </div>
      </td>
    </tr>
    <tr>
      <td align="left"><em>*Harus diisi</em></td>
      <td colspan="3" align="right"><input name="jenis" type="hidden" id="jenis" value="4" />
      <input name="Simpan" type="submit" id="Simpan" value="Simpan Pembayaran" /></td>
    </tr>
  </table>
</form>